#include <stdio.h>
#include <unistd.h>
#include <fcntl.h>
#include <sys/types.h>
#include <sys/stat.h>

#define BUFFER_NUM 1024

int main(int argc, char *argv[])
{
	int read_fd, write_fd;
	int read_num;
	char buf[BUFFER_NUM];
	if (argc != 3) //判断参数数目
	{
		printf("Parameter num error!\n");
		exit(-1);
	}
	if ((read_fd = open(argv[1], O_RDONLY)) == -1) //打开源文档
	{
		perror("Open error");
		exit(-1);
	}
	if ((write_fd = open(argv[2], O_WRONLY | O_CREAT, S_IRUSR | S_IWUSR)) == -1)
	{
		perror("Create destination file error");
		exit(-1);
	}
	while (read_num = read(read_fd, buf, BUFFER_NUM))
	{
		if (read_num == -1)
		{
			perror("Read error");
			exit(-1);
		}
		else if (write(write_fd, buf, read_num) == -1)
		{
			perror("Write error");
			exit(-1);
		}
	}
	close(read_fd);
	close(write_fd);
	return 0;
}